package com.ag.lzw.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbUser;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.common.IPermissionService;
import com.ag.lzw.dao.LzwTbUserDAO;
import com.ag.lzw.service.TaskTrackHandel;
import com.ag.lzw.service.impl.Lzw_IIDServiceImpl;
import com.ag.lzw.vo.FeedBackVo;

/**
 * 任务反馈的Action
 * 
 * @author 钟龙伟
 */
@Scope("prototype")
@Controller("handelFeedbackAction")
public class HandelFeedbackAction extends BaseAction implements SessionAware{
	private static final long serialVersionUID = 891781047149206372L;
	private static final Logger logger = Logger.getLogger(HandelFeedbackAction.class);
	
	/**
	 * 调用权限服务逻辑组件
	 */
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;
	/**
	 * 提供Map<String, Object>类型的Session变量，用来保存Struts2注入的Session上下文
	 */
	private Map<String, Object> sessionMap;
	
    @Resource(name="lzw_IIDServiceImpl")
	private Lzw_IIDServiceImpl idSerImpl;
    @Resource(name="TaskTrackHandelImpl")
	private TaskTrackHandel taskTrackHandel;
    
	private Map<String, String> queryOption;  //接收页面传过来的参数
	
	private String ajaxString;
	
	private String toid;
	private String cuname;
	
	//添加反馈前的查询动作
	public String addFeedback(){
		TbUser user = pms.getCurrentUser(sessionMap); // 获取当前用户信息
		String cUname = user.getUName();
		this.setCuname(cUname);
		this.setToid(toid);
		return "get_feed_back";
	}
	
	//添加反馈的方法
	public String saveFeedback(){
		this.ajaxString="0";
		logger.info("Save Feedback!");
		String fbId = idSerImpl.findFeedBackPK(IDUtil.TB_TASK_FEEDBACK);
		
		if(fbId!=null){
			logger.info("get new feedback id:"+fbId);
			FeedBackVo fbv = new FeedBackVo();
			fbv.setTfId(fbId);
			if(queryOption.containsKey("tid")){
				fbv.setTid(queryOption.get("tid").toString());
			}
			if(queryOption.containsKey("tfPeople")){
				fbv.setTfPeople(queryOption.get("tfPeople").toString());
			}
			if(queryOption.containsKey("tfTime")){
				fbv.setTfTime(queryOption.get("tfTime").toString());
				logger.info("feedback date:"+queryOption.get("tfTime").toString());
			}
			if(queryOption.containsKey("tfText")){
				fbv.setTfText(queryOption.get("tfText").toString());
			}
			if(queryOption.containsKey("tfNote")){
				fbv.setTfNote(queryOption.get("tfNote").toString());
			}
			if(queryOption.containsKey("tfannex")){
				logger.info("annex"+queryOption.get("tfannex").toString());
				fbv.setTfAnnex(queryOption.get("tfannex").toString());
			}
			if(queryOption.containsKey("tfannexid")){
				logger.info("annexid:"+queryOption.get("tfannexid").toString());
				fbv.setTfAnnexId(queryOption.get("tfannexid").toString());
			}
		    
			if(taskTrackHandel.saveFeedBack(fbv)){
				this.ajaxString="0";
				return "feed_back_succ";
			} else {
				//返回信息1代表保存反馈失败
				this.ajaxString="1";
				return "feed_back_false";
			}
		} else {
			//返回信息2代表分配ID失败
			this.ajaxString="2";
			return "feed_back_false";
		}

	}

	
	public String getFeedback(){
		TbUser user = pms.getCurrentUser(sessionMap); // 获取当前用户信息
		String cUname = user.getUName();
		this.setCuname(cUname);
		this.setToid(toid);
		return "get_feed_back";
	}

	public Map<String, String> getQueryOption() {
		return queryOption;
	}

	public void setQueryOption(Map<String, String> queryOption) {
		this.queryOption = queryOption;
	}

	public String getAjaxString() {
		return ajaxString;
	}

	public void setAjaxString(String ajaxString) {
		this.ajaxString = ajaxString;
	}

	public String getToid() {
		return toid;
	}

	public void setToid(String toid) {
		this.toid = toid;
	}

	public String getCuname() {
		return cuname;
	}

	public void setCuname(String cuname) {
		this.cuname = cuname;
	}
	@Override
	public void setSession(Map<String, Object> session) {
		this.sessionMap = session;

	}
	
}
